import * as vscode from 'vscode';
import { USER_COMMANDS } from '../../command_names';
import { EXECUTE_JSON_CHILDREN, CONFIG_NAMESPACE, EXECUTE_REQUEST_CHILDREN } from '../../constants';
import { UtilityQuery } from '../../gitlab/utility_query';
import { ItemModel } from './../items/item_model';
import { UnilityJsonChildrenItem } from './unility_json_children_item';
import { UnilityRequestChildrenItem } from './unility_request_children_item';
export class UtilityItem extends ItemModel {
  private name: string;

  private type: string;
  constructor(
    name: string,
    type: string,
  ) {
    super();
    this.name = name;
    this.type = type;
  }

  getTreeItem(): vscode.TreeItem {
    const item = new vscode.TreeItem(
      this.name,
      vscode.TreeItemCollapsibleState.Collapsed,
    );
    item.iconPath = new vscode.ThemeIcon('filter');
    return item;
  }

  async getChildren(): Promise<UnilityJsonChildrenItem[] | UnilityRequestChildrenItem[]> {
    if (this.type == 'json_format'){
      const customQueries =
      vscode.workspace
        .getConfiguration(CONFIG_NAMESPACE)
        .get<UtilityQuery[]>(EXECUTE_JSON_CHILDREN) || [];
      const items = customQueries.map(q => new UnilityJsonChildrenItem(q.name, q.type));
      return items;
    }else {
      const customQueries =
        vscode.workspace
          .getConfiguration(CONFIG_NAMESPACE)
          .get<UtilityQuery[]>(EXECUTE_REQUEST_CHILDREN) || [];
      const items = customQueries.map(q => new UnilityRequestChildrenItem(q.name, q.type));
      return items;
    }
  }
}
